package com.adinnet.admin.video.service.impl;

import com.adinnet.admin.video.model.Video;
import com.adinnet.admin.video.mapper.VideoMapper;
import com.adinnet.admin.video.service.VideoService;
import com.adinnet.admin.word.model.Word;
import com.adinnet.core.JsonResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 视频表 服务实现类
 * </p>
 *
 * @author zYshuai
 * @since 2020-12-11
 */
@Service
public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements VideoService {

    @Autowired
    private VideoMapper videoMapper;


    /**
     * @param keyword:
     * @Description: 视音频列表
     * @author zYshuai
     * @Date: 2020/12/15 10:01
     * @return: java.util.List<com.adinnet.admin.video.model.Video>
     */
    @Override
    public List<Video> videoList(String keyword) {
        return videoMapper.selectList(new QueryWrapper<Video>().eq("deleted", 0).eq(StringUtils.isNotBlank(keyword), "video_name", keyword).orderByDesc("created_date"));
    }

    /**
     * @param videoId:
     * @Description: 删除视音频
     * @author zYshuai
     * @Date: 2020/12/15 10:02
     * @return: com.adinnet.core.JsonResult
     */
    @Override
    public JsonResult delete(Integer videoId) {
        Video video = new Video();
        video.setDeleted(true);
        videoMapper.update(video, new QueryWrapper<Video>().eq("id", videoId));
        return JsonResult.ok("删除成功");
    }
}
